﻿@model BI.CF.Model.UserrsModel

@{
    ViewBag.Title = "PayPwd";
    Layout = "~/Views/Shared/MasterView.cshtml";
}

<h2>PayPwd</h2>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>

<style>
    .span {
        color:#ff0000;
    }
</style>

<div>
    <form action="/" method="post">
        <input hidden id="pwd" name="pwd" value="@Model.PaymentPwd" />
        <input hidden id="id" name="id" value="@Model.UserId" />
        <div id="divAdd1" hidden>
            <table>
                <tr>
                    <td>支付密码</td>
                    <td><input type="text" id="pwd1" /></td>
                    <td><span id="s1" class="span"></span></td>
                </tr>
                <tr>
                    <td>确认支付密码</td>
                    <td><input type="text" id="pwd2" /></td>
                    <td><span id="s2" class="span"></span></td>
                </tr>
                <tr>
                    <td><input type="button" name="btn" value="确认" onclick="btnfun()" /></td>
                    <td></td>
                </tr>
            </table>
        </div>
        <div id="divAdd2" hidden>
            <table>
                <tr>
                    <td>原支付密码</td>
                    <td><input type="text" id="pwd3" onblur="PwdQuery()" /></td>
                    <td><span id="s3" class="span"></span></td>
                </tr>
                <tr>
                    <td>新支付密码</td>
                    <td><input type="text" id="pwd4" /></td>
                    <td><span id="s4" class="span"></span></td>
                </tr>
                <tr>
                    <td>再次确认</td>
                    <td><input type="text" id="pwd5" /></td>
                    <td><span id="s5" class="span"></span></td>
                </tr>
                <tr>
                    <td><input type="button" name="btn" value="确认修改" onclick="btnfun()" /></td>
                    <td></td>
                </tr>
            </table>
        </div>
    </form>
</div>
<script>

    $(function () {
        var pwd = $("#pwd").val();
        if (pwd == 0) {
            $("#divAdd1").show();
            //$("#divAdd2").hide();
            //$(divAdd2).addClass = "none";
        }
        else {
            //$(divAdd1).addClass = "none";
            $("#divAdd2").show();
            //$("#divAdd1").hide();
        }
    })


    function btnfun() {
        var pwd1 = $("#pwd1").val();
        var pwd2 = $("#pwd2").val();
        var pwd3 = $("#pwd3").val();
        var pwd4 = $("#pwd4").val();
        var pwd5 = $("#pwd5").val();

        if (pwd3 == "" && pwd4 == "" && pwd5 == "") {
            if (pwd1 == "") {
                $("#s1").html("支付密码不能为空")
                return;
            }
            else if(pwd1.length!=6)
            {
                $("#s1").html("密码长度不正确")
                return;
            }
            else {
                $("#s1").html("")
            }

            if (pwd2 == "") {
                $("#s2").html("确认密码不能为空")
                return;
            }
            else if (pwd2.length != 6) {
                $("#s2").html("密码长度不正确")
                return;
            }
            else {
                $("#s2").html("")
            }

            if (pwd1 != pwd2)
            {
                $("#s1").html("密码与确认密码不一致")
                return;
            }


            $.ajax({
                url: '/MyAccount/PayPwdEdit',
                type: 'post',
                data: {
                    PaymentPwd: pwd2
                },
                success: function (mes) {
                    if (mes = 1) {
                        alert("设置完成")
                        location.href = '/MyAccount/MyAccountIndex'
                    }
                    else {
                        alert('错误')
                    }
                }

            })
        }
        else {
            if (pwd3 == "") {
                $("#s3").html("原密码不能为空")
                return;
            }
            else if (pwd3.length != 6) {
                $("#s3").html("密码长度不正确")
                return;
            }
            else {
                $("#s3").html("")
            }

            if (pwd4 == "") {
                $("#s4").html("新密码不能为空")
                return;
            }
            else if (pwd4.length != 6) {
                $("#s4").html("密码长度不正确")
                return;
            }
            else {
                $("#s4").html("")
            }

            if (pwd5 == "") {
                $("#s5").html("确认密码不能为空")
                return;
            }
            else if (pwd5.length != 6) {
                $("#s5").html("密码长度不正确")
                return;
            }
            else {
                $("#s5").html("")
            }
         
            if (pwd4 != pwd5)
            {
                $("#s4").html("密码与确认密码不一致")
            }

            $.ajax({
                url: '/MyAccount/PayPwdEdit2',
                type: 'post',
                data: {
                    PaymentPwd: pwd4
                },
                success: function (mes) {
                    if (mes = 1) {
                        alert("设置完成")
                        location.href = '/MyAccount/MyAccountIndex'
                    }
                    else {
                        alert('错误')
                    }
                }

            })
        }
               
    }
    function PwdQuery()
    {
        $.ajax({
            url: '/MyAccount/PwdQuery',
            type: 'post',
            data: {
                PaymentPwd: $("#pwd3").val(),
                Userid:$("#id").val()
            },
            success: function (mes)
            {
                if (mes == 0) {
                    $("#s3").html("用户支付密码不正确")
                    return;
                }
                else {
                    $("#s3").html()
                }
            }
        })
    }
</script>